/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
//package oop.demo.bankingtasklistgui;
package top.anka1.ims.BankingTaskListGUI;

/**
 * Manages individual account details.
 * @author ashongtical
 * @author Anka
 */
public class BankAccount {
    private Double balance;
    private Integer depositsCount;
    private Integer withdrawalsCount;
    private Double annualInterestRate;
    private Double monthlyServiceCharges;
    
    //initialise by setting values of balance, annual Interest Rate, deposit count, monthlyservice charges, withdrawal count
    public BankAccount(double balance, double annualInterestRate) {
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
        this.depositsCount = 0;
        this.withdrawalsCount = 0;
    }

    // The Deposit method to put 
    // check if amount to be deposited is 0 or less otherwise add amount to balance
    // Adds money to the account and increments deposit count.
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            depositsCount++;
        } else {
            System.out.println("Deposit amount must be positive.");
            throw new IllegalArgumentException("Deposit amount must be positive.");
        }
    }

    // Withdraw method to take money from the bank
    // check if balance is less than RMB 25 and deny withdrawal
    // Deducts money from the account and increments withdrawal count.
    public void withdraw(double amount) {
        if (amount > 0 && balance - amount >= 25) {
            balance -= amount;
            withdrawalsCount++;
        } else if (balance < 25) {
            System.out.println("Insufficient funds. Minimum balance of RMB 25 required.");
            throw new IllegalArgumentException("Insufficient funds. Minimum balance of RMB 25 required.");
        } else {
            System.out.println("Withdrawal amount must be positive.");
            throw new IllegalArgumentException("Withdrawal amount must be positive.");
        }
    }

    // Calculates monthly interest and updates the balance.
    public double calcInterest() {
        double monthlyInterestRate = annualInterestRate / 12;
        double interest = balance * monthlyInterestRate;
        balance += interest;
        return interest;
    }

    // Monthly processing
    // Applies service charges, resets counters, and updates the balance.
    public void monthlyProcess() {
        if (depositsCount > 0) {
            monthlyServiceCharges += 0.10 * depositsCount;
        }
        if (withdrawalsCount > 0) {
            monthlyServiceCharges += 0.25 * withdrawalsCount;
        }
        if (balance < 25) {
            monthlyServiceCharges += 5;
        }
        balance -= monthlyServiceCharges;
        calcInterest();
        depositsCount = 0;
        withdrawalsCount = 0;
        monthlyServiceCharges = 0.0;
        System.out.println("Monthly processing completed.");
    }

    // Accounts become inactive if the balance drops below RMB 25.00. Transactions are restricted until the balance exceeds RMB 25.00.
    public boolean AccountStatus() {
        return balance > 25;
    }
    // Display account details
    public void displayAccountDetails() {
        System.out.println("Balance: RMB " + balance);
        System.out.println("Deposits this month: " + depositsCount);
        System.out.println("Withdrawals this month: " + withdrawalsCount);
    }

    // Getters and Setters
    public double getBalance() {
        return balance;
    }
    public void setBalance(double balance) {
        this.balance = balance;
    }
    public double getAnnualInterestRate() {
        return annualInterestRate;
    }
    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }
    public int getDepositsCount() {
        return depositsCount;
    }
    public void setDepositsCount(int depositsCount) {
        this.depositsCount = depositsCount;
    }
    public int getWithdrawalsCount() {
        return withdrawalsCount;
    }
    public void setWithdrawalsCount(int withdrawalsCount) {
        this.withdrawalsCount = withdrawalsCount;
    }
    public double getMonthlyServiceCharges() {
        return monthlyServiceCharges;
    }
    public void setMonthlyServiceCharges(double monthlyServiceCharges) {
        this.monthlyServiceCharges = monthlyServiceCharges;
    }
}
